'''
Created on Apr 12, 2011

@author: mwarren1
'''
import wx

class CommandDialog(wx.Dialog):
    '''
    classdocs
    '''

    def __init__(self, parent, label, commandText):
        '''
        Constructor
        '''
        self.textBoxInitialValue = commandText
        
        winSize = wx.Size(400,285)
        label1Text = 'Enter commands to be run after emails are downloaded from label "' + label + '"\n(One command per line)'
        label2Text = 'To Print Downloaded Files, use keyword "print"' + "\n" + \
                              'To Delete Downloaded Files, use keyword "delete"' + "\n" + \
                              'To Exit After Download, use keyword "exit"' + "\n" + \
                              '*Any Other Command will be executed in Command Prompt*' + "\n" + \
                              '*In Commands, the keyword "%filename" will be replaced by file\'s name'
        
        if 'wxGTK' in wx.PlatformInfo:
            winSize = wx.Size(455,320)
            label1Text = 'Enter commands to be run after emails are downloaded\nfrom label "' + label + '"\n(One command per line)'
            label2Text = 'To Delete Downloaded Files, use keyword "delete"' + "\n" + \
                              'To Exit After Download, use keyword "exit"' + "\n" + \
                              '*Any Other Command will be executed in Command Prompt*' + "\n" + \
                              '*In Commands, the keyword "%filename" will be replaced by\n   file\'s name'
                              
        if 'wxMac' in wx.PlatformInfo:
            winSize = wx.Size(455,320)
            label1Text = 'Enter commands to be run after emails are downloaded\nfrom label "' + label + '"\n(One command per line)'
            label2Text = 'To Delete Downloaded Files, use keyword "delete"' + "\n" + \
                              'To Exit After Download, use keyword "exit"' + "\n" + \
                              '*Any Other Command will be executed in Command Prompt*' + "\n" + \
                              '*In Commands, the keyword "%filename" will be replaced by\n   file\'s name'
        
        wx.Dialog.__init__(self, 
                           parent, 
                           id = -1,
                           title = 'Commands for "' + label + '" label',
                           size = winSize)
        
        self.textBox = wx.TextCtrl(self,
                              id = -1,
                              value = self.textBoxInitialValue,
                              size = (winSize.x - 25,100),
                              style = wx.TE_MULTILINE)
        
        label1 = wx.StaticText(self,
                      id = -1,
                      label = label1Text)
        
        label2 = wx.StaticText(self,
                      id = -1,
                      label = label2Text)
        
        okBUTTON = wx.Button(self, wx.ID_OK, "OK")
        cancelBUTTON = wx.Button(self, wx.ID_CANCEL, "Cancel")
        
        buttonSizer = wx.StdDialogButtonSizer()
        buttonSizer.AddButton(okBUTTON)
        buttonSizer.AddButton(cancelBUTTON)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        
        sizer.Add(label1, 0, wx.ALL, 10)
        
        sizer.Add(self.textBox, 0, wx.LEFT, 10)

        sizer.Add(label2, 0, wx.LEFT, 20)        
        

        sizer.AddSpacer((2,2))
        sizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, 10)
        
        buttonSizer.Realize()
        buttonSizer.SetDimension(380, 230, -1, -1)
        
        self.SetSizer(sizer)
        
    def GetValue(self):
        if self.ReturnCode == wx.ID_OK:
            return self.textBox.GetValue()
        if self.ReturnCode == wx.ID_CANCEL:
            return self.textBoxInitialValue

if __name__ == "__main__":
    
    app = wx.App(False)
    
    commandText = "Test Command"
    label = "Dropbox"
    
    dlg = CommandDialog(None, label, commandText)
    
    dlg.ShowModal()
    commandText = dlg.GetValue() 
    print commandText
    
    dlg.Destroy()